package com.iwhalecloud.bss.kite.cucc.web.controller.order;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.iwhalecloud.bss.kite.client.dto.DataResult;
import com.iwhalecloud.bss.kite.common.constant.ErrorConsts;
import com.iwhalecloud.bss.kite.common.constant.KeyConsts;
import com.iwhalecloud.bss.kite.cucc.client.api.inf.IInfBcmcServiceBus;
import com.iwhalecloud.bss.kite.cucc.client.vo.scene.SceneNewOfferSeneVO;
import com.iwhalecloud.bss.kite.cucc.web.service.IBcmcSceneService;
import com.iwhalecloud.bss.kite.manager.transaction.KiteTransactional;
import com.ztesoft.bss.common.util.ContextUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/bcmcOrder")
@Api(tags = {
    "/bcmcOrder - BCMC订单信息"
})
public class BcmcOrderController {

    @Autowired
    private IInfBcmcServiceBus orderService;

    @Autowired
    private IBcmcSceneService bcmcSceneService;

    @KiteTransactional
    @ApiOperation(value = "获取订单详情", notes = "获取订单详情")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "orderId", value = "订单标识", required = true)
    })
    @GetMapping("/detail")
    public DataResult<Map<String, Object>> getWorkOrderInfo(@RequestParam String orderId) {
        return ErrorConsts.SUCCESS.getResult(orderService.getWorkOrderInfo(orderId));
    }

    @SuppressWarnings("deprecation")
    @KiteTransactional
    @ApiOperation(value = "获取订单信息生成场景视图", notes = "根据订单ID和服务提供获取订单信息对应场景视图")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "orderId", value = "订单中心的订单ID", required = true),
        @ApiImplicitParam(name = "serviceOfferId", value = "服务提供", required = true)
    })
    @GetMapping("/orderDetailSceneView")
    public DataResult<SceneNewOfferSeneVO> getOrderDetailSceneView(@RequestParam String orderId,
        @RequestParam String serviceOfferId) {

        // 1.根据工单信息创建场景
        String sceneInstId = bcmcSceneService
            .createOfferSceneByOrderDetailInfo(orderId, serviceOfferId, "", "", ContextUtil.getUserId().toString(),
                ContextUtil.getLandId(), ContextUtil.getLoginInfo().getUserInfo().getPostRegionId().toString(),
                KeyConsts.KITE_SCENE_INST_OPER_TYPE_1000)
            .getResultObject();

        // 2.工单场景信息展示
        return bcmcSceneService.getOrderSceneInfoView(sceneInstId);

    }

}
